﻿using GN.Pay.Client.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Client.Utils
{
    /// <summary>
    /// 服务帮助
    /// </summary>
    public static class ServiceUtils
    {
        /// <summary>
        /// 创建服务
        /// </summary>
        /// <param name="payConfigure"></param>
        /// <returns></returns>
        public static IServiceClient CreateServiceClient(IPayConfigure payConfigure)
        {
            return new ServiceClient(payConfigure);
        }

        /// <summary>
        /// 创建服务,默认从配置文件读取
        /// </summary>
        /// <returns></returns>
        public static IServiceClient CreateServiceClient()
        {
            return new ServiceClient(PayConfigureUtils.ConfigFileToPayConfigure());
        }

        /// <summary>
        /// 检查支付配置
        /// </summary>
        /// <param name="payConfigure"></param>
        /// <returns></returns>
        public static IPayConfigure CheckPayConfigure(IPayConfigure payConfigure)
        {
            ExceptionUtils.CheckNotNull(payConfigure, nameof(payConfigure));
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(payConfigure.AppId, nameof(payConfigure.AppId));
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(payConfigure.AppKey, nameof(payConfigure.AppKey));
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(payConfigure.MerchantId, nameof(payConfigure.MerchantId));
            ExceptionUtils.CheckNotNullOrNotWhiteSpace(payConfigure.ServerUrl, nameof(payConfigure.ServerUrl));
            return payConfigure;
        }
    }
}
